//
//  ViewController.m
//  UI15-网易新闻
//
//  Created by 韩旭 on 16/8/3.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"
#import "HX_CollectionViewCell.h"
#import "SelfSizeTools.h"
#import "HX_CollectionLayout.h"
#import "HX_CollectionLayoutCell.h"
#define kCollectionView @"reuse"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, HX_CollectionLayoutDelegate>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *arr;
@property (nonatomic, strong) UICollectionView *collection;
@property (nonatomic, strong) UILabel *label;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.navigationItem.title = @"网易新闻";
//    scrollView 自动边距
//    遇到状态栏，导航栏，自动为页面上的某一个scrollView添加
//    一般我们在开发中关闭这个属性
//    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor greenColor];
//    自适应：
//    [self creatCollectionView];
//    自定义Layouts
    [self creatCollectionViewLayout];
}

- (void)creatCollectionViewLayout {
    self.arr = [NSArray array];
    HX_CollectionLayout *layout = [[HX_CollectionLayout alloc] init];
    _collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight * 0.05) collectionViewLayout:layout];
    [_collection registerClass:[HX_CollectionLayoutCell class] forCellWithReuseIdentifier:@"ce"];
    layout.delegate = self;
    _collection.backgroundColor = [UIColor whiteColor];
    [self.view addSubview: _collection];
    _collection.delegate = self;
    _collection.dataSource = self;
    self.arr = @[@"头条", @"精选", @"娱乐", @"体育", @"网易号", @"本地", @"视频", @"财经", @"科技", @"汽车", @"时尚", @"图片", @"直播", @"热点", @"跟贴"];
}

- (void)creatCollectionView {
    self.arr = [NSArray array];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(50, 50);
    layout.scrollDirection = 1;
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight * 0.05) collectionViewLayout:layout];
    _collectionView.backgroundColor = [UIColor lightGrayColor];
    [_collectionView registerClass:[HX_CollectionViewCell class] forCellWithReuseIdentifier:kCollectionView];
    [self.view addSubview:_collectionView];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    self.arr = @[@"头条", @"精选", @"娱乐", @"体育", @"网易号", @"本地", @"视频", @"财经", @"科技", @"汽车", @"时尚", @"图片", @"直播", @"热点", @"跟贴"];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _arr.count;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout width:(CGFloat)width sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return [SelfSizeTools selfSizeHeightWithString:_arr[indexPath.item] Width:50 Font:[UIFont systemFontOfSize:17]];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HX_CollectionLayoutCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ce" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor lightGrayColor];
    cell.lable.text = _arr[indexPath.item];
    return cell;
}
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
//    NSString *string = _arr[indexPath.item];
//    CGFloat width = [SelfSizeTools selfSizeHeightWithString:string Width:50 Font:[UIFont systemFontOfSize:17]];
//    return CGSizeMake(width, 50);
//}
@end